{% extends front.html %}

{% block title %}{{ options.site_name }} - {{ tsk.taskname }} - 迅雷离线下载分享{% end %}
{% block desc %}{% if tsk.tags %}TAGS:{{ ", ".join(tsk.tags) }}{% end %} UP主:{{ not tsk.invalid and email2name(tsk.creator) or "unknow" }}{% end %}

{% block more_head %}
<script src="http://pstatic.xunlei.com/js/base64.js"></script>
<script type="text/javascript" src="{{static_url('js/common.js')}}"></script>
<script type="text/javascript">
  LE.taskname = {% raw json_encode(tsk.taskname) %};
  LE.links = function () {
    var result = [];
    $.each($(".share-file-title"), function(i, n) {
      n = $(n);
      result.push({url: n.attr("href"), title: n.text()});
    });
    return result;
  };
  LE.cookie = "{{ cookie }}".split(";")[0];
  LE.show = function(str) {
    $.fancybox('<textarea id="link-text" style="width: 700px; height: 320px;">'+str+'</textarea>');
  };
  LS.share_url = {% raw json_encode(request.protocol+"://"+request.host+"/share/"+str(task_ids)) %};
  LS.share_title = {% raw json_encode(tsk.taskname+u" - 迅雷离线下载分享 - "+options.site_name) %};
</script>
<link rel="canonical" href="{{ request.protocol }}://{{ request.host }}/share/{{ task_ids }}" />
{% end %}

{% block info %}
{% if options.using_xss or handler.installed_userjs() %}
{% raw modules.TagList() %}
{% else %}
{% include info.html %}
{% end %}
<a class="goback" href="/"><div id="goback-button">&lt;- 回到首页</div></a>
{% end %}

{% block list %}
{% if not options.using_xss and not handler.disabled_userjs() and handler.get_cookie("xss") != gdriveid %}
  {% set iframe_src = "%s#cross-cookie|%s://%s/xss?gdriveid=%s" % (options.cross_cookie_url, request.protocol, request.host, gdriveid) %}
  <div class="cross-cookie hidden" data-version="{{ options.cross_cookie_version }}"></div>
  <script src="/xss_check.js?gdriveid={{ gdriveid }}"></script>
  <iframe src="{{ iframe_src }}" style="display: none;"></iframe>
{% end %}

<!--share bar-->
<ul class="task-list">
    <li class="push-top"></li>
    <div id="share-button" class="task-button">
      <a href="/share/{{ task_ids }}" target="_blank"><div>分享</div></a>
      <div id="share-links" class="more-links" style="display: none;">
        <a href="javascript:LS.share_google();" title="分享到 Google+"><div class="task-button">Google+</div></a>
        <a href="javascript:LS.share_twitter();" title="分享到 Twitter+"><div class="task-button">Twitter</div></a>
        <a href="javascript:LS.share_sina();" title="分享到 新浪微博"><div class="task-button">新浪微博</div></a>
        <a href="javascript:LS.share_qq();" title="分享到 腾讯微博"><div class="task-button">腾讯微博</div></a>
        <a href="javascript:LS.share_douban();" title="分享到 豆瓣"><div class="task-button">豆瓣</div></a>
      </div>
    </div>
    <div id="batch-button" class="task-button">
      <div>批量下载</div>
      <div id="batch-links" class="more-links" style="display: none;">
        <a href="javascript:LE.wget_links();"><div class="task-button">wget</div></a>
        <a href="javascript:LE.aria2_links();"><div class="task-button">aria2x10</div></a>
        <a href="javascript:LE.lixian_links();"><div class="task-button">迅雷导出</div></a>
        <a href="/export/{{ url_escape(options.site_name) }}_idm_{{ task_ids }}.ef2"><div class="task-button">IDM 导出</div></a>
        <a href="/export/{{ url_escape(options.site_name) }}_orbit_{{ task_ids }}.olt"><div class="task-button">Orbit导出</div></a>		
        <a href="/export/{{ url_escape(options.site_name) }}_aria2c_{{ task_ids }}_.down"><div class="task-button">aria2导出</div></a>
      </div>
    </div>
    <div class="clearfix"></div>
    </li>
    <li class="push-bottom"></li>
</ul>
<!--share bar end-->

<!--traverse task-->
{% for task, files in tasks %}
<!--<span class="infohash" style="float: right;">Hash: {{ task.cid }}</span>-->
<ul class="task-list">
  
  <li class="share-task-item">
    {% if task.status in ('waiting', 'downloading') %}
    <div class="process-bar {{ task.status }}" style="width: {{ 100-task.process }}%"></div>
    {% end %}
    <div class="share-tname">{{ task.taskname }}</div>
    <div class="info">
        <span class="date">{{ task.createtime.strftime("%Y-%m-%d") }}</span>
        <span class="file-size">{{ format_size(task.size) }}</span>
    </div>
  <!--<div class="ext-info">
    
    <span class="uploader">UP主: {{ not task.invalid and email2name(task.creator) or "unknow" }}</span>
    {% if task.tags %}
    <span class="tags">TAGS: {% raw modules.TagsModule(task.tags) %}</span>
    {% end %}
  </div>-->
    <div class="clearfix"></div>
  </li>

  {% for file in files %}
  <li class="file-item">
    {% if file.status in ('waiting', 'downloading') %}
    <div class="process-bar {{ file.status }}" style="width: {{ 100-file.process }}%"></div>
    {% end %}
    {% if file.lixian_url %}
    <a class="share-file-title" href="{{ file.lixian_url }}" target="_blank" title="{{ file.title }}"><div class="tname"><span class="p1">{{ len(file.title) > 15 and file.title[:-15] or file.title }}</span><span class="p2">{{ len(file.title) > 15 and file.title[-15:] or "" }}</span></div></a>
    {% else %}
    <div class="tname"><span class="p1">{{ len(file.title) > 15 and file.title[:-15] or file.title }}</span><span class="p2">{{ len(file.title) > 15 and file.title[-15:] or "" }}</span></div>
    {% end %}
    <div class="info"><span class="file-size">{{ format_size(file.size) }}</span></div>
    <div class="add2lixian task-button" style="display:none;"><a>使用迅雷下载</a></div>
    <div class="clearfix"></div>
  </li>
  {% end %}
  
</ul>
{% end %}
<!--traverse task end-->

<div class="hidden"><textarea id="link-text" style="width: 700px; height: 320px;"> </textarea></div>
<div class="hidden">
  <a href="#disabled_cross_cookie" id="disable-helper"></a>
  <div id="disabled_cross_cookie">
    <dl>
      <dd>您已经禁用或尚未安装跨站Cookie脚本，无法使用浏览器直接下载。</dd>
      <dt>
        <ul>
          <li><a href="javascript:$.fancybox.close();">好吧，我使用批量下载功能下载</a></li>
          <li><a href="{{ options.cross_userscript }}" target="_blank">我要使用浏览器直接下载资源</a></li>
        </ul>
      </dt>
    </dl>
  </div>
</div>
{% end %}

{% block foot %}
<script type="text/javascript">
  function _gc(name) {
    return document.getElementsByClassName(name);
  }
  var OnResize = function() {
    var tnames = _gc("tname");
    for(var i=0; i<tnames.length; i++) {
      var tname = tnames[i];
      if (tnames[i].offsetWidth-200 < tnames[i].firstChild.offsetWidth) {
        tnames[i].lastChild.setAttribute("style", "right: 0;");
      } else {
        tnames[i].lastChild.removeAttribute("style");
      }
    }
  }
  OnResize();
  window.onresize = OnResize;

  $("#batch-button").hover(function() {
    $("#batch-links").show();
  }, function() {
    $("#batch-links").hide();
  });

  $("#share-button").hover(function() {
    $("#share-links").show();
  }, function() {
    $("#share-links").hide();
  });

  $(".file-item").hover(function() {
    var _this = $(this);
    var t = _this.find(".share-file-title");
    if (t) {
      if(!_this.find(".file-2lixian a").attr("href"))
        _this.find(".add2lixian a").attr("href", thunder_url_fix(t.attr("href"), t.text()));
      _this.find(".add2lixian").show()
    }
  }, function() {
      $(this).find(".add2lixian").hide()
  })

  if (localStorage && LE.custom_script) {
    var custom = '<a id="custom-button" href="javascript:LE.custom();"><div class="task-button">'+LE.custom_script.name+'</div></a>';
    $("#batch-links").prepend(custom);
  }

  $("#wget-button").fancybox({onStart: LE.wget_links});  
  $("#aria2-button").fancybox({onStart: LE.aria2_links});  
  $("#disable-helper").fancybox();
  {% if handler.disabled_userjs() %}
  $("a.file-title").click(function() {
    $("#disable-helper").click();
    return false;
  });
  {% end %}
</script>
<script>
  {% if options.using_xss %}
  if ($.browser.msie){ 
    document.write('<script type="text/javascript" src="/xssjs?v=2"><\/script>');
  } else {
    document.write('<script type="text/javascript" src="/xssjs"><\/script>');
  }
  {% end %}
</script>
{% end %}
